var a = new(require("../../../utils/http").HTTP);
let {
  channel
} = require("../../../api/attract/qd_content")
let {
  intention,
  getsjxq,
  linkmans,
  getFllowDetail
} = require("../../../api/attract/select");
Page({
  data: {
    xxbtshow: false,
    dkShow: false,
    xqList: [],
    // 客户
    khly: [],
    khyxdj: [],
    infor: [],
    Info: wx.getStorageSync("userInfoMy"),
    detail: {},
    show: !1,
    collected: !0,
    zanwu: !0,
    attract: ["基本信息", "联系信息", "跟进记录"],
    investment: 0,
    follow: {},
    linkman: []
  },
  formatTime(Time, type = 1) {
    // console.log(Time)
    let date = new Date(Time)
    const year = date.getFullYear();
    const month = (date.getMonth() + 1).toString().padStart(2, '0');
    const day = date.getDate().toString().padStart(2, '0');
    const hour = date.getHours().toString().padStart(2, '0');
    const minute = date.getMinutes().toString().padStart(2, '0');
    const second = date.getSeconds().toString().padStart(2, '0');
    if (type == 1) {
      return `${year}-${month}-${day}`;

    } else {
      return `${year}-${month}-${day} ${hour}:${minute}:${second}`;
    }

  },
  xxbtClick() {
    this.setData({
      xxbtshow: !this.data.xxbtshow
    })
  },
  goLookDk(e) {
    let {
      type
    } = e.currentTarget.dataset
    let infor = wx.getStorageSync('infor')
    switch (type) {

      case 'bk':
        let gxsj = this.formatTime(this.data.follow.gjsj, 2)
        wx.navigateTo({
          url: `/pages/channel/follow_dk/follow?khbh=${this.data.detail.qdbh}&bid=${this.data.follow.bid}&affiliation=inner&tjsj=${gxsj}`,
        })
        break;
      default:
        break;
    }
  },
  lxrshowC(e) {
    let {
      index,
      booll
    } = e.currentTarget.dataset
    let IndexB = `linkman[${index}].BooleanLxr`
    this.setData({
      [IndexB]: !booll
    })
  },
  opendak() {
    this.setData({
      dkShow: !this.data.dkShow
    })
  },
  goLook(e) {
    let {
      type,
      lid
    } = e.currentTarget.dataset;
    if (type == 1) {
      wx.navigateTo({
        url: `/pages/intention/contact/contact?IID=${lid}`,
      });
    } else {
      wx.navigateTo({
        url: "/pages/intention/compile/compile?lID=" + lid,
      });
    }
  },

  topChange: function (t) {
    var a = t.currentTarget.dataset.index;
    this.setData({
      investment: a,
    });
  },
  onLoad: function (t) {
    var d = this;
    console.log(t.qdid)
    channel(3, t.qdid).then((function (a) {
      d.setData({
        detail: a.data[0]
      })
      a.data[0].bID = a.data[0].qdID
      a.data[0].khbh = a.data[0].qdbh
      wx.setStorageSync('infor', a.data[0])
      wx.setStorageSync('qymclxr', a.data[0].qymc)

      linkmans(a.data[0].qdbh).then(function (res) {
        res.data.forEach(item => {
          item.BooleanLxr = false
        })
        d.setData({
          linkman: res.data,
        });

      });
      getFllowDetail(t.qdid, a.data[0].qdbh).then(res => {
        d.setData({
            follow: res.data[0],
          })
          let NTime=d.formatTime(res.data[0].gjsj,2)
          d.setData({
            'follow.gjsjN':NTime

          })
          res.data.length > 0 &&
          d.setData({
            zanwu: !0,
          });
        null == d.data.follow &&
          d.setData({
            zanwu: !1,
          });
      })
    }))

  },
  goQdEdit: function () {

    wx.navigateTo({
      url: "/pages/channel/editchannel/editchannel?detail=" + JSON.stringify(this.data.detail)
    })
  },
  test: function () {
    wx.navigateTo({
      url: "/pages/channel/addservice/addservice?id=" + this.data.detail.qdbh + "&qymc=" + this.data.detail.qymc + "&whry=" + this.data.detail.whry + "&qdid=" + this.data.detail.qdid
    })
  },
  onShow: function () {

  }
});